class Solution(object):
    base = 1337
    def powMod(self, a, b):
        a = a % self.base
        ret = 1
        for _ in range(b):
            ret = ret * a % self.base
        return ret

    def superPow(self, a, b):
        """
        :type a: int
        :type b: List[int]
        :rtype: int
        """
        if len(b)==0:
            return 1
        i = b[-1]
        b.pop(-1)
        return self.powMod(self.superPow(a, b), 10) * self.powMod(a, i) % self.base
    
print(Solution().superPow(2, [3]))